package com.estar.assistsurvy.activity.app;

import java.util.concurrent.TimeUnit;

import org.litepal.LitePalApplication;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.SDKInitializer;
import com.estar.assistsurvy.R;
import com.estar.assistsurvy.utils.CrashHandler;
import com.iflytek.cloud.SpeechUtility;
import com.m7.imkfsdk.utils.FaceConversionUtil;
import com.socks.okhttp.plus.OkHttpProxy;

import android.app.Application;
import cn.jpush.android.api.JPushInterface;
import okhttp3.OkHttpClient;

public class AssistSurvyApp extends LitePalApplication {
	
	private static AssistSurvyApp mobileApplication;
    //客服SDK是否已经初始化过了
    public static boolean isKFSDK = false;
    
    
    private BMapManager mBMapManager;
	 
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		mobileApplication = this;
		//初始化表情,界面效果需要
        new Thread(new Runnable() {
            @Override
            public void run() {
                FaceConversionUtil.getInstace().getFileText(
                		AssistSurvyApp.getInstance());
            }
        }).start();
		mBMapManager = new BMapManager();
		SDKInitializer.initialize(getApplicationContext());
		mBMapManager.getContext();
		JPushInterface.setDebugMode(false); // 设置开启日志,发布时请关闭日志
		JPushInterface.init(this); // 初始化 JPush
		LitePalApplication.initialize(this);
		OkHttpClient.Builder builder = OkHttpProxy.getInstance().newBuilder().connectTimeout(90, TimeUnit.SECONDS)
				.readTimeout(90, TimeUnit.SECONDS).writeTimeout(90, TimeUnit.SECONDS);

		// ignore HTTPS Authentication
		// builder.hostnameVerifier(new MyHostnameVerifier());
		// try {
		// SSLContext sc = SSLContext.getInstance("TLS");
		// sc.init(null, new TrustManager[]{new MyTrustManager()}, new
		// SecureRandom());
		// builder.sslSocketFactory(sc.getSocketFactory());
		// } catch (NoSuchAlgorithmException e) {
		// e.printStackTrace();
		// } catch (KeyManagementException e) {
		// e.printStackTrace();
		// }

		// 应用程序入口处调用，避免手机内存过小，杀死后台进程后通过历史intent进入Activity造成SpeechUtility对象为null
		// 如在Application中调用初始化，需要在Mainifest中注册该Applicaiton
		// 注意：此接口在非主进程调用会返回null对象，如需在非主进程使用语音功能，请增加参数：SpeechConstant.FORCE_LOGIN+"=true"
		// 参数间使用半角“,”分隔。
		// 设置你申请的应用appid,请勿在'='与appid之间添加空格及空转义符

		// 注意： appid 必须和下载的SDK保持一致，否则会出现10407错误

		SpeechUtility.createUtility(AssistSurvyApp.this, "appid=" + getString(R.string.app_id));

		// 以下语句用于设置日志开关（默认开启），设置成false时关闭语音云SDK日志打印
		// Setting.setShowLog(false);

		OkHttpProxy.setInstance(builder.build());
		
		//全局收集异常信息的单例类
		CrashHandler crashHandler=CrashHandler.getInstance();//这是收集异常信息的单例类
		crashHandler.init(getApplicationContext());//初始化

//		PgyCrashManager.register(this);
		
	}
	
	public static AssistSurvyApp getInstance() {
        return mobileApplication;
    }
}
